public class text14 {
    public static void main(String[] args) throws InterruptedException {
        // 创建三个线程
        Thread tc = new Thread(() -> {
            // 打印c
            System.out.print(Thread.currentThread().getName() + " ");
        }, "c");

        Thread tb = new Thread(() -> {
            try {
                // 等待c 执行完成
                tc.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 打印b
            System.out.print(Thread.currentThread().getName() + " ");
        }, "b");

        Thread ta = new Thread(() -> {
            try {
                // 等待b 执行完成
                tb.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 打印a
            System.out.print(Thread.currentThread().getName() + " ");
        }, "a");

        // 需要让他们同时启动，并按 c，b，a的顺序打印
        tc.start();
        ta.start();
        tb.start();
        //tc.start();
    }

    public static void main1(String[] args) {
        Object lock1=new Object();
        Object lock2=new Object();
        Thread a=new Thread(()->{
            System.out.println("a");
            synchronized (lock1) {
                lock1.notify();
            }

        });
        Thread b=new Thread(()->{
            try {
                synchronized (lock1) {
                    lock1.wait();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("b");
            synchronized (lock2) {
                lock2.notify();
            }

        });
        Thread c=new Thread(()->{
            try {
                synchronized (lock2) {
                    lock2.wait();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("c");

        });
        b.start();
        c.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        a.start();

    }
}
